package baduga.karo;
import java.awt.Toolkit;

import baduga.client.Player_Constans;
import baduga.core.*;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

//okienko "Raise"

/**
* @author Karolina
*/

public class Raise extends javax.swing.JFrame {

		   
		private static final long serialVersionUID = 1L;
		private JTextField textField;
		
		
		private int playerBiD = -1;
		
		private JLabel lblPodajLiczbetonw;
		
		//zmiana ikonki na pasku tytyłu
		
		/**
		 * Tryb pokazania okna
		 * 
		 * 1 - Bet
		 * 2 - Raise
		 * 
		 * @param mode
		 */
	    public Raise(int mode) {
			setIconImage(Toolkit.getDefaultToolkit().getImage(AboutAuthorsScreen.class.getResource("/baduga/karo/resources/icon.png")));
	        initComponents(mode);
	    }

	    //@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
	    private void initComponents(int mode) {
	    	
	    	
	    	String title = "";

	        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
	        
	        if(mode == 1)
	        {
	        	title = "Bet";
	        }
	        else if(mode == 2)
	        {
	        	title = "Raise";
	        }
	        
	        setTitle(title);
	        setResizable(false);
	        
	        
	        title = null;
	        

	        lblPodajLiczbetonw = new JLabel("Podaj ilość " + Core_Messages.getMessage(0x0000) + " o jaką chcesz zwiększyć zakład ( 0, " + Player_Constans.getCash() + "]");

	        
	        
	        
	        
	        textField = new JTextField();
	        textField.setColumns(10);

	        
	        //obsługa przycisków "ok" i "anuluj"
	        
	        JButton btnOk = new JButton("OK");
	        btnOk.addActionListener(new ActionListener() {
	        	public void actionPerformed(final ActionEvent arg0) {
	        		
	        		int amountCash = 0;
	        		boolean parseState = true;
	        			        			
	        		try {
	        			 amountCash = Integer.parseInt(textField.getText());
	        		}
	        		catch(NumberFormatException ex){
	        			JOptionPane.showMessageDialog(null, "Wprowadzona liczba nie jest tekstem");
	        			parseState = false;
	        		}
	        		
	        		
	        		if(parseState == true)
	        		{
	        			
	        			if(amountCash > 0  && amountCash <= Player_Constans.getCash() )
	        			{
	        				playerBiD = amountCash;	
	        				dispose();
	        			}
	        			else
	        			{
	        				playerBiD = -1;
	        				JOptionPane.showMessageDialog(null, "Wartośc spoza zakresu");
	        			}
	        		}
	        		else
	        		{
	        			playerBiD = -1;
	        		}
	        		
	        		
	        	}
	        });
	        
	        
	        JButton btnAnuluj = new JButton("Anuluj");
	        btnAnuluj.addActionListener(new ActionListener() {
	        	public void actionPerformed(ActionEvent arg0) {
	        		dispose();
	        	}
	        });
	        
	        
	      
	        //własności okna
	        
	        final GroupLayout layout = new GroupLayout(getContentPane());
	        layout.setHorizontalGroup(
	        	layout.createParallelGroup(Alignment.LEADING)
	        		.addGroup(layout.createSequentialGroup()
	        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
	        				.addGroup(layout.createSequentialGroup()
	        					.addGap(84)
	        					.addComponent(btnOk, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
	        					.addGap(18)
	        					.addComponent(btnAnuluj))
	        				.addGroup(layout.createSequentialGroup()
	        					.addGap(30)
	        					.addGroup(layout.createParallelGroup(Alignment.LEADING, false)
	        						.addComponent(lblPodajLiczbetonw, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
	        						.addComponent(textField, GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE))))
	        			.addContainerGap(40, Short.MAX_VALUE))
	        );
	        layout.setVerticalGroup(
	        	layout.createParallelGroup(Alignment.LEADING)
	        		.addGroup(layout.createSequentialGroup()
	        			.addGap(20)
	        			.addComponent(lblPodajLiczbetonw, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
	        			.addPreferredGap(ComponentPlacement.RELATED)
	        			.addComponent(textField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
	        			.addGap(18)
	        			.addGroup(layout.createParallelGroup(Alignment.LEADING)
	        				.addComponent(btnAnuluj)
	        				.addComponent(btnOk))
	        			.addContainerGap(13, Short.MAX_VALUE))
	        );
	        getContentPane().setLayout(layout);

	        pack();
	    }

	  
	    /**
	     * Zwraca wartość jaką ustawił gracz
	     * 
	     * -1  = rezygnacja
	     * 
	     * @return
	     */
	    public int getPlayerBid()
	    {
	    	return playerBiD;
	    }
	}


